﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class Base<T> where T:Base
    {
        private Model1 model {
            get {
                return new Model1();
            }
        }

        public bool insert(params T[] t) {
            var mo = model;
            mo.Set<T>().AddRange(t);
            int a = mo.SaveChanges();
            return a > 0;
        }

        public T Tiao(Expression<Func<T,bool>> expression) {
            return model.Set<T>().SingleOrDefault(expression);
        }

        public List<T> Select(Expression<Func<T, bool>> expression) {
            return model.Set<T>().Where(expression).ToList();
        }

        public bool delect(T t) {
            var con = model;
            con.Set<T>().Remove(t);
            return con.SaveChanges() > 0;
        }
    }
}
